package com.gaff.emp.core.hbase.desc;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class HBaseTableDesc {

    /**
     * 命名空间
     */
    private String namespaceName;

    /**
     * 表名
     */
    private String tableName;

    /**
     * Region最大大小
     */
    private long maxFileSize;

    /**
     * 内存刷新大小
     */
    private long memStoreFlushSize;

    /**
     * Region副本数
     */
    private int regionReplication;

    /**
     * 是否压缩
     */
    private boolean compression;

    /**
     * 是否规范化
     */
    private boolean normalization;

    /**
     * 是否只读
     */
    private boolean readonly;

    /**
     * 是否禁用
     */
    private boolean disabled;

    /**
     * 是否为MetaTable
     */
    private boolean metaTable;

    private Map<String, String> tableProps;

    private List<HBaseColumnFamilyDesc> columnFamilyDescList;

    /**
     * 最后主要压缩时间戳
     */
    private long lastMajorCompactTimestamp;

    private String tableDesc;

    public HBaseTableDesc addProp(String key, String value) {
        if (tableProps == null) {
            this.tableProps = new HashMap<>();
        }
        if (StrUtil.isBlank(key)) {
            return this;
        }
        if (value == null) {
            value = "";
        }
        this.tableProps.put(key, value);
        return this;
    }

    public String tablePropsToString() {
        if (tableProps == null || tableProps.isEmpty()) {
            return "";
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, String> entry : tableProps.entrySet()) {
            stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append(";");
        }
        return stringBuffer.substring(0, stringBuffer.length() - 1).toString();
    }

}
